class Solution
{
public:
    int minimumSeconds(vector<int> &nums)
    {
        unordered_map<int, vector<int>> numPos;
        int n = nums.size();
        for (int i = 0; i < n; ++i)
        {
            numPos[nums[i]].push_back(i);
        }

        int result = INT_MAX;
        for (auto &[_, pos] : numPos)
        {
            int l = pos.size();
            pos.push_back(pos[0] + n);
            int m = 0;
            for (int i = 0; i < l; ++i)
            {
                int interval = pos[i + 1] - pos[i];
                m = max(m, interval / 2);
            }
            result = min(result, m);
        }
        return result;
    }
};